package com.kindness.frate.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewGroup;

/**
 * Created by Administrator on 2017/7/28 0028.
 * 加入阻尼效果
 */
public class VPRecyclerView extends RecyclerView {

    PullZoomVPScroll pullZoomVPScroll;

    public VPRecyclerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouchEvent(MotionEvent e) {
        if(!pullZoomVPScroll.canScroll()){
            return false;
        }
        return super.onTouchEvent(e);
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        ViewGroup viewGroup = (ViewGroup) getParent();
        while (true){
            if(viewGroup instanceof PullZoomVPScroll){
                pullZoomVPScroll = (PullZoomVPScroll) viewGroup;
                break;
            }
            viewGroup = (ViewGroup) viewGroup.getParent();
        }
    }
}
